Skip to content

fix(scripts): Show git checkout error output on branch creation failure#2082

Closed
grafvonb wants to merge 1 commit intogithub:mainfrom
grafvonb:main
Closed

fix(scripts): Show git checkout error output on branch creation failure#2082
grafvonb wants to merge 1 commit intogithub:mainfrom
grafvonb:main

Conversation

@grafvonb
Copy link
Copy Markdown
Contributor

@grafvonb grafvonb commented Apr 3, 2026

Summary

Improves error reporting in create-new-feature.sh by displaying actual git error messages instead of silently discarding them.

Problem

When git checkout -b or git checkout failed, stderr was discarded with 2>/dev/null. This left users without diagnostic information to troubleshoot issues like:

  • Uncommitted changes blocking checkout
  • Merge conflicts
  • Permission problems
  • Detached HEAD states

Solution

  • Capture stderr from git checkout commands using file descriptor redirection
  • Display the captured error message when operations fail
  • Preserve existing error handling logic and exit codes

Testing

Tested by attempting branch operations with:

  • Dirty working tree (shows "Please commit your changes or stash them")
  • Existing branch without --allow-existing-branch flag

@grafvonb grafvonb requested a review from mnriem as a code owner April 3, 2026 16:21
Copilot AI review requested due to automatic review settings April 3, 2026 16:21
Copy link
Copy Markdown
Collaborator

@mnriem mnriem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will also have to deliver the Powershell variant

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves diagnostics in scripts/bash/create-new-feature.sh so users can see the underlying git checkout error output when branch creation/switching fails, aiding troubleshooting during feature branch setup.

Changes:

  • Captures git checkout stderr into a variable instead of discarding it.
  • Prints the captured stderr when branch creation/switching fails, while keeping existing branching logic and exit behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +296 to 299
$checkoutStderr = ''
try {
git checkout -q -b $branchName 2>$null | Out-Null
$checkoutStderr = git checkout -q -b $branchName 2>&1 | Out-String
if ($LASTEXITCODE -eq 0) {
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$checkoutStderr = git checkout ... 2>&1 | Out-String captures both stdout and stderr (it merges streams), so the variable name is a bit misleading and future changes to the git flags could accidentally include non-error output in the “stderr” blob. Consider either redirecting stdout away (while preserving stderr capture) or renaming the variable to reflect that it’s combined output.

Copilot uses AI. Check for mistakes.
Previously, stderr from git checkout was discarded (2>/dev/null),
leaving users without diagnostic information when branch operations
failed. Now captures and displays the actual git error message to
help troubleshoot issues like conflicts or dirty working trees.
@mnriem
Copy link
Copy Markdown
Collaborator

mnriem commented Apr 3, 2026

Please address Copilot feedback. Probably should reflect it is both

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants